def Prosto(n):
    t=True
    for i in range(2,int(n**0.5)+1):
        if n%i=0:
            t=False
    return t 
s=input()
aif=['one','two','three','four','five','six','seven','eight','nine']
s=split()
if (s[0] in alf) and (s[1]in alf) and (s[2]in alf):
    chislo=alf.index(s[a]*100+alf.index(s[1]*10*+alf.index(s[2])
    if Prosto(chislo):
        p=chislo
    else:
        for i in range(chislo -1,2 ,-1)
            if Prosto(i):
                p=i
                break
        for i in range(chislo+1,1500):
            if Prosto(i) and (chislo-p) >
            > (i-chislo):
                 p=i
                 break
                 print(p)
    else: print ('Wrong input')